package cz.vargarob.spring.aop.repo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Repository;

import cz.vargarob.spring.aop.entity.Person;

@Repository
public class PersonRepositoryStubImpl implements PersonRepository {

	@SuppressWarnings("serial")
	private List<Person> people = new ArrayList<Person>() {
	{
		add (new Person ("Robert", "Varga"));
		add (new Person ("Gabriel", "Varga"));
		add (new Person ("Gejza", "Varga"));
		add (new Person ("Robert", "Kovac"));
	}};
	
	public List<Person> getAll() {
		return Collections.unmodifiableList(people);
	}
	
	public List<Person> getAllByLastName(String lastName) {
		List<Person> result = new ArrayList<Person>();
		for (Person p: people){
			if (lastName.equals(p.getSurname())){
				result.add(p);
			}
		}
		return result;
	}
	
	public List<Person> getAllByFirstName(String firstName) {
		List<Person> result = new ArrayList<Person>();
		for (Person p: people){
			if (firstName.equals(p.getName())){
				result.add(p);
			}
		}
		return result;
	}

}
